package com.share.finance.risk.rules.utils;

import org.kie.api.io.Resource;
import org.kie.api.io.ResourceType;
import org.kie.internal.io.ResourceFactory;
import org.springframework.util.CollectionUtils;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class KieUtil {

    //drl文件转resource类
    public static List<Resource> drls2KieResource(Map<String, String> drls) {
        List<Resource> reList = new LinkedList<>();
        if (!CollectionUtils.isEmpty(drls)) {
            for (Map.Entry<String, String> entries : drls.entrySet()) {
                String key = entries.getKey();
                String value = entries.getValue();

                Resource resource = ResourceFactory.newByteArrayResource(value.getBytes());
                resource.setResourceType(ResourceType.DRL);
                resource.setSourcePath(key + ".drl");
                reList.add(resource);
            }
        }

        return reList;
    }
}
